<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>31.set集合实践</title>
</head>
<body>
    <script>
        let arr = [1,2,3,4,5,4,3,2,1];
        //1. 利用set数组去重
        let result = [...new Set(arr)];
        console.log(result);
        //2. 交集
        let arr2 = [4,5,6,7,8];
        /* let res = [...new Set(arr)].filter(item =>{
            let s2 = new Set(arr2);  // 4 5 6
            if(s2.has(item)){
                return true;
            }else{
                return false;
            }
        }) */
        let res = [...new Set(arr)].filter(item=> new Set(arr2).has(item));
        console.log(res);
        //3. 并集
        let res2 = [...result,...new Set(arr2)];
        console.log(res2);
        //4. 差集  差集指 在我这有 不能在你那有
        let res3  = result.filter(item => !(new Set(arr2).has(item)));
        console.log(res3); 
    </script>
</body>
</html>